﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProceduralTexture : MonoBehaviour {
    public int resolution = 512;
    private Material m_Mat;

    private void Start() {
        m_Mat = GetComponent<MeshRenderer>().sharedMaterial;
        var tex = GenerateParabola();
        m_Mat.SetTexture("_MainTex", tex);
    }

    private Texture2D GenerateParabola() {
        var tex = new Texture2D(resolution, resolution);
        var uvCenter = new Vector2(.5f, .5f);
        var pxCenter = uvCenter * resolution;

        for(int x = 0; x < resolution; x++) {
            for(int y = 0; y < resolution; y++) {
                var uvDist = Vector2.Distance(new Vector2(x, y), pxCenter) / resolution * 2;

                uvDist = Mathf.Abs(1 - Mathf.Clamp01(uvDist));
                uvDist = Mathf.Sin(uvDist * 10f);

                var c = new Color(uvDist, uvDist, uvDist, 1f);
                tex.SetPixel(x, y, c);
            }
        }
        tex.Apply();
        return tex;
    }
}
